{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Sum of Squares of Special Elements "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: sumOfSquares"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #特殊元素平方和"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>1</strong> 开始、长度为 <code>n</code> 的整数数组 <code>nums</code> 。</p>\n",
    "\n",
    "<p>对 <code>nums</code> 中的元素 <code>nums[i]</code> 而言，如果 <code>n</code> 能够被 <code>i</code> 整除，即 <code>n % i == 0</code> ，则认为 <code>num[i]</code> 是一个 <strong>特殊元素</strong> 。</p>\n",
    "\n",
    "<p>返回 <code>nums</code> 中所有 <strong>特殊元素</strong> 的 <strong>平方和</strong> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,2,3,4]\n",
    "<strong>输出：</strong>21\n",
    "<strong>解释：</strong>nums 中共有 3 个特殊元素：nums[1]，因为 4 被 1 整除；nums[2]，因为 4 被 2 整除；以及 nums[4]，因为 4 被 4 整除。 \n",
    "因此，nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21 。  \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [2,7,1,19,18,3]\n",
    "<strong>输出：</strong>63\n",
    "<strong>解释：</strong>nums 中共有 4 个特殊元素：nums[1]，因为 6 被 1 整除；nums[2] ，因为 6 被 2 整除；nums[3]，因为 6 被 3 整除；以及 nums[6]，因为 6 被 6 整除。 \n",
    "因此，nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63 。 </pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length == n &lt;= 50</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 50</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [sum-of-squares-of-special-elements](https://leetcode.cn/problems/sum-of-squares-of-special-elements/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [sum-of-squares-of-special-elements](https://leetcode.cn/problems/sum-of-squares-of-special-elements/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,3,4]', '[2,7,1,19,18,3]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        s=0\n",
    "        for i,v in enumerate(nums,start=1):\n",
    "           if n%i==0:\n",
    "               s+=v*v\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        return sum(nums[i] * nums[i] for i in range(0, n) if n % (i + 1) == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans,l = 0,len(nums)\n",
    "        for i in range(l):\n",
    "            if not l % (i+1):\n",
    "                ans += nums[i] ** 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for i in range(len(nums)):\n",
    "            if len(nums) % (i+1) == 0:\n",
    "                res += nums[i] * nums[i];\n",
    "\n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x*x for i,x in enumerate(nums,1) if len(nums)%i==0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range( n):\n",
    "            if n % (i + 1) == 0:\n",
    "                ans += (nums[i] * nums[i])\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(val * val for i, val in enumerate(nums, 1) if len(nums) % i == 0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans, n = 0, len(nums)\n",
    "        for i in range(1, isqrt(n) + 1):\n",
    "            if n % i == 0:\n",
    "                ans += nums[i - 1] ** 2  # 注意数组的下标还是从 0 开始的\n",
    "                if i * i < n:  # 避免重复统计\n",
    "                    ans += nums[n // i - 1] ** 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(nums)):\n",
    "            if len(nums) % (i + 1) == 0:\n",
    "                ans += nums[i] ** 2\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        return sum((nums[i]*nums[i] for i in range(n) if n % (i+1) == 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        n = len(nums)\n",
    "        for i, num in enumerate(nums, 1):\n",
    "            if n % i == 0:\n",
    "                res += num * num\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        l = len(nums)\n",
    "        res = 0\n",
    "        for i in range(l):\n",
    "            if l % (i+1) ==0:\n",
    "                res += nums[i]*nums[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans, n = 0, len(nums)\n",
    "        for i in range(1, isqrt(n) + 1):\n",
    "            if n % i == 0:\n",
    "                ans += nums[i - 1] ** 2  # 注意数组的下标还是从 0 开始的\n",
    "                if i * i < n:  # 避免重复统计\n",
    "                    ans += nums[n // i - 1] ** 2\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans, n  = 0, len(nums)\n",
    "        for i in range(1,n+1):\n",
    "            if n%i == 0:\n",
    "                ans += nums[i-1]**2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans, length = 0, len(nums)\n",
    "        for i in range(1, length+1):\n",
    "            if length % i ==0: ans += nums[i-1]*nums[i-1]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        res = 0\n",
    "        for i,x in enumerate(nums):\n",
    "            if n % (i+1) == 0:\n",
    "                res += x**2\n",
    "        return res \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        n = len(nums)\n",
    "        for i in range(1, n + 1):\n",
    "            if n % i == 0:\n",
    "                ans += nums[i - 1] ** 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        cnt, i = 0, 0\n",
    "        n = len(nums)\n",
    "        while i < n:\n",
    "            if n % (i+1) == 0:\n",
    "                cnt += nums[i] * nums[i]\n",
    "            i += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x * x for i,x in enumerate(nums,1) if len(nums)%i == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        result = 0\n",
    "        for i in range(1, n + 1):\n",
    "            if n % i == 0:\n",
    "                result += nums[i - 1] * nums[i - 1]\n",
    "        return result\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        cnt = 0\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            if n % (i+1) == 0:\n",
    "                cnt += nums[i] * nums[i]\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(1, int(n**0.5+1)):\n",
    "            if n % i == 0:\n",
    "                ans += nums[i-1] ** 2\n",
    "                if i * i < n:  # 避免重复统计\n",
    "                    ans += nums[n // i - 1] ** 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x * x for i, x in enumerate(nums,1) if len(nums) % i ==0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        summ = 0\n",
    "        for i in range(len(nums)):\n",
    "            if n%(i+1)==0:\n",
    "                summ += nums[i]**2\n",
    "        \n",
    "        return summ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x * x for i, x in enumerate(nums) if len(nums) % (i + 1) == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        res = 0\n",
    "        for i in range(n):\n",
    "            if n % (i + 1) == 0:\n",
    "                res += nums[i] ** 2\n",
    "        return res\n",
    "            \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "         return sum(x * x for i, x in enumerate(nums, 1)\n",
    "                if len(nums) % i == 0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        square_sum = 0\n",
    "        n = len(nums)\n",
    "        for i in range(1, n+1):\n",
    "            if n % i == 0:\n",
    "                square_sum += nums[i-1] * nums[i-1]\n",
    "        return square_sum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        s = 0\n",
    "        for i in range(len(nums)):\n",
    "            # print(3)\n",
    "            if (len(nums)%(i+1)) == 0:\n",
    "                s+=nums[i]**2\n",
    "        \n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        a=[]\n",
    "        n=len(nums)\n",
    "        for i in range(n):\n",
    "            if n%(i+1)==0:\n",
    "                a=a+[nums[i]**2]\n",
    "        return sum(a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        square_sum = 0\n",
    "        n = len(nums)\n",
    "        for i in range(1, n+1):\n",
    "            if n % i == 0:\n",
    "                square_sum += nums[i-1] * nums[i-1]\n",
    "        return square_sum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        res = 0\n",
    "        for i in range(1,n+1):\n",
    "            if n % i == 0:\n",
    "                res += nums[i-1]**2\n",
    "        return res \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        n = len(nums)\n",
    "        for i,x in enumerate(nums):\n",
    "            if n % (i+1) ==0:\n",
    "                res += x**2\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        sum = 0\n",
    "        n = len(nums)+1\n",
    "        for i in range(1,len(nums)+1):\n",
    "            if len(nums) % i == 0:\n",
    "                sum = sum + nums[i-1]*nums[i-1]\n",
    "        return sum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        result=0\n",
    "        for i in range(len(nums)):\n",
    "            if len(nums) % (i+1) == 0:\n",
    "                result+=nums[i]*nums[i]\n",
    "            else:\n",
    "                pass\n",
    "        return result\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i,x in enumerate(nums,1):\n",
    "            if n % i == 0:\n",
    "                ans += x*x\n",
    "        return ans\n",
    "                \n",
    "         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        n=len(nums)\n",
    "        for i in range(1,n+1):\n",
    "            if n%i==0:\n",
    "                ans+=nums[i-1]**2\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans, n = 0, len(nums)\n",
    "        for i in range(1, isqrt(n) + 1):\n",
    "            if n % i == 0:\n",
    "                ans += nums[i - 1] ** 2  # 注意数组的下标还是从 0 开始的\n",
    "                if i * i < n:  # 避免重复统计\n",
    "                    ans += nums[n // i - 1] ** 2\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        sum=0\n",
    "        for i in range(len(nums)):\n",
    "            if len(nums) % (i+1)==0:\n",
    "                sum+=nums[i]**2\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(nums[i] * nums[i] for i in range(len(nums)) if len(nums) % (i + 1) == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            if n % (i+1) == 0:\n",
    "                ans += nums[i] ** 2\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        special = []\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            if n % (i+1) == 0:\n",
    "                special.append(nums[i]*nums[i])\n",
    "\n",
    "        return sum(special)        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            if not n % (i+1) :\n",
    "                ans += nums[i] * nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(0, len(nums)):\n",
    "            if n % (i + 1) == 0:\n",
    "                ans += nums[i] * nums[i]\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        n = len(nums)\n",
    "        for i, num in enumerate(nums):\n",
    "            if n % (i+1) == 0:\n",
    "                ans += num*num\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        sum = 0\n",
    "        for i, v in enumerate(nums):\n",
    "            if n % (i+1) == 0:\n",
    "                sum += v ** 2\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        square_all = 0\n",
    "        for i, num in enumerate(nums):\n",
    "            if n % (i+1) == 0:\n",
    "                square_all = square_all + num * num\n",
    "        return square_all        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans, n = 0, len(nums)\n",
    "        for i in range(len(nums)):\n",
    "            if n % (i + 1) == 0:\n",
    "                ans += nums[i] * nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        cnt, i = 0, 0\n",
    "        n = len(nums)\n",
    "        while i < n:\n",
    "            if n % (i+1) == 0:\n",
    "                cnt += nums[i] * nums[i]\n",
    "            i += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        sum = 0\n",
    "        n = len(nums)\n",
    "        for i in range(1,n+1):\n",
    "            if n % i == 0:\n",
    "                sum += nums[i-1]**2\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        n=len(nums)\n",
    "        for j,num in enumerate(nums):\n",
    "            if n%(j+1)==0:\n",
    "                ans+=num**2\n",
    "        return ans\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        \n",
    "        for i in range(1, len(nums)+1):\n",
    "            if len(nums) % i == 0:\n",
    "                ans += nums[i-1] ** 2\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        res = 0\n",
    "        for i in range(n):\n",
    "            if n % (i + 1) == 0:\n",
    "                res += nums[i] ** 2\n",
    "        return res\n",
    "            \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        n=len(nums)\n",
    "        for j,num in enumerate(nums):\n",
    "            if n%(j+1)==0:\n",
    "                ans+=num**2\n",
    "        return ans\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            if n % (i + 1) == 0:\n",
    "                ans += nums[i] ** 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = [nums[i]**2 for i in range(n) if n%(i + 1)==0]\n",
    "        return sum(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(0, len(nums)):\n",
    "            if n % (i + 1) == 0:\n",
    "                ans += nums[i] * nums[i]\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x * x for i, x in enumerate(nums, 1)\n",
    "                         if len(nums) % i == 0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        #模拟即可\n",
    "        ans,n=0,len(nums)\n",
    "        for i in range(1,n+1):\n",
    "            if n%i==0: ans+=pow(nums[i-1],2)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x ** 2 for i, x in enumerate(nums, 1) if len(nums) % i == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        res=0\n",
    "        for i,v in enumerate(nums):\n",
    "            if n%(i+1)==0:\n",
    "                res+=v*v\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        target = 0\n",
    "        for i in range(len(nums)):\n",
    "            if len(nums) % (i+1) == 0:\n",
    "                target += nums[i]**2\n",
    "        return target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        sum=0\n",
    "        n=len(nums)\n",
    "        for i in range(1,n+1):\n",
    "            if n%i==0:\n",
    "                sum=sum+nums[i-1]**2\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[-1] ** 2\n",
    "    \n",
    "        total = 0\n",
    "        for i in range(1,len(nums)//2+1):\n",
    "            if len(nums)%i==0:\n",
    "                total += nums[i-1] ** 2\n",
    "    \n",
    "        return total + nums[-1] ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(x * x for i, x in enumerate(nums, 1)\n",
    "                         if len(nums) % i == 0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(num ** 2 for i, num in enumerate(nums) if not len(nums) % (i + 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum([nums[i]**2 for i in range(len(nums)) if len(nums)%(i+1)==0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        a=len(nums)\n",
    "        result=0\n",
    "        for i in range(1,a+1):\n",
    "            if a%i == 0:\n",
    "                result=result+nums[i-1]*nums[i-1]\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        temp = [nums[i] for i in range(len(nums)) if len(nums)%(1+i)==0]\n",
    "        return sum(list(map(lambda x: x**2,temp)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            if n % (i+1) :\n",
    "                continue\n",
    "            else:\n",
    "                ans += nums[i] ** 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        return sum(nums[num-1]*nums[num-1] for num in range(1,len(nums)+1) if len(nums) % num == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            if n%(i+1)==0:ans += nums[i]**2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        ans=0\n",
    "        for i in range(n):\n",
    "            if n%(i+1)==0:\n",
    "                ans+=nums[i]*nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfSquares(self, nums: List[int]) -> int:\n",
    "        sum=0\n",
    "        n=len(nums)\n",
    "        for i in range(n):\n",
    "            if n%(i+1)==0:\n",
    "                sum += nums[i]**2\n",
    "        return sum\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
